package com.walsai.pcsys.core.dao.hibernate;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

import com.walsai.pcsys.core.dao.ContestDao;
import com.walsai.pcsys.core.model.Contest;
import com.walsai.pcsys.core.model.Solution;
import com.walsai.pcsys.core.model.User;

public class ContestDaoHibernate extends GenericDaoHibernate<Contest, Long> implements
		ContestDao {

	public ContestDaoHibernate() {
		super(Contest.class);
		// TODO Auto-generated constructor stub
	}

	@Override
	public List<Contest> getContests(User u) {
		Session s = this.getSession();
		List list = null;
		try {
			list = s.createCriteria(Solution.class).add(Restrictions.eq("solutionPK.user", u)).list();
		} catch (HibernateException e) {
			e.printStackTrace();
		} finally {
			if (s != null) {
				try {
					s.close();
				} catch (HibernateException e) {
					e.printStackTrace();
				}
			}
		}

		return list;
	}

}
